/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objective;

/**
 *
 * @author daz
 */
public class XInSet implements IObjective {

    private int violateDegreees;
    private int x;
    private int[] set;

    public XInSet(int x, int[] set) {
        this.x = x;
        this.set = set;
        this.violateDegreees = calculateViolation(x, set);

    }

    private int calculateViolation(int x, int[] set) {
        int result = 1;
        for (int i = 0; i < set.length; i++) {
            if (x == set[i]) {
                result = 0;
                break;
            }
        }
        return result;
    }

    @Override
    public int getAssignDelta(int index, int newValue) {
        if (index == -1) {
            x = newValue;
        } else {
            set[index] = newValue;
        }
        return calculateViolation(x, set) - violateDegreees;
    }

    @Override
    public int getViolateDegrees() {
        return this.violateDegreees;
    }
}
